package com.wangzh.collection;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

public class CollectionDemo {
    public static void main(String[] args) {
        Collection<String> coll = new ArrayList<>();

        coll.add("aa");
        coll.add("bb");
        coll.add("cc");
        coll.add("dd");

        Iterator<String> iterator = coll.iterator();
        while (iterator.hasNext()) {
            String next = iterator.next();
            System.out.println(next);
        }

        for (String s : coll) {
            s = "as";
        }

//        Collection<Data> coll2 = new ArrayList<>();
////        coll2.add(new Data("a"));
////        coll2.add(new Data("b"));
////        coll2.add(new Data("c"));
////        for (Data data : coll2) {
////            data.setName("ass");
////        }

        Collection<Integer> coll2 = new ArrayList<>();
        coll2.add(Integer.valueOf(10));
        coll2.add(Integer.valueOf(11));
        coll2.add(Integer.valueOf(12));
        for (Integer i : coll2) {
            System.out.println(i.hashCode());
            i=Integer.valueOf(15);
        }

        System.out.println(coll2);
    }

}
class Data{
    private String name;


    public Data() {
    }

    public Data(String name) {
        this.name = name;
    }

    /**
     * 获取
     * @return name
     */
    public String getName() {
        return name;
    }

    /**
     * 设置
     * @param name
     */
    public void setName(String name) {
        this.name = name;
    }

    public String toString() {
        return "Data{name = " + name + "}";
    }
}
